#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/12/9 21:14
# @Author  : 新猿异码
# @Site    : https://gitee.com/chshao/autotest
# @CSDN    : https://blog.csdn.net/m0_37576542?type=blog
# @File    : TestModel.py
# @Desc    : 模块功能描述
# @Software: PyCharm
import os
from autotest.buildin.database.DBClient import Model
from autotest.buildin.database.DBClient import CharField
from autotest.buildin.database.DBClient import TextField
from autotest.buildin.database.DBClient import IntegerField
from autotest.buildin.database.DBClient import DateTimeField
from autotest.buildin.database.DBClient import FloatField
from autotest.buildin.database.DBClient import SqliteDataBase

from autotest.kernel.modle.Variable import Var
db_sqlite = SqliteDataBase(os.path.join(os.path.split(Var.Project.ReportPath)[0], "report.db"))


class Task(Model):

    task_id = CharField(max_length=25, null=False, unique=True, verbose_name="任务编号")
    start_time = DateTimeField(verbose_name="开始时间")
    end_time = DateTimeField(verbose_name="结束时间")
    total = IntegerField(default=0, verbose_name="用例总数")
    passed = IntegerField(default=0, verbose_name="通过用例数")
    failed = IntegerField(default=0, verbose_name="失败用例数")
    block = IntegerField(default=0, verbose_name="阻塞用例数")
    not_run = IntegerField(default=0, verbose_name="未执行用例数")
    tester = CharField(max_length=50, verbose_name="测试人员")
    desc = TextField(verbose_name="任务描述")
    pass_rate = FloatField(default=0, verbose_name="用例通过率")

    class Meta:
        database = db_sqlite


class TestCase(Model):

    task_id = CharField(max_length=25, null=False, verbose_name="任务编号")
    case_id = CharField(max_length=100, null=False, verbose_name="用例编号")
    module = CharField(max_length=25, verbose_name="用例所属模块")
    desc = CharField(max_length=100, verbose_name="用例描述")
    detail = TextField(verbose_name="用例详细信息")
    start_time = DateTimeField(verbose_name="开始时间")
    end_time = DateTimeField(verbose_name="结束时间")
    result = CharField(max_length=10, default="NotRun", verbose_name="用例执行结果")
    run_log = TextField(verbose_name="运行日志")
    err_msg = TextField(default="无", verbose_name="错误信息")
    other_msg = TextField(verbose_name="预留")

    class Meta:
        database = db_sqlite


if __name__ == '__main__':
    Task.insert(task_id="4565464643").execute()

